<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门名称数据-->
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="name"
            placeholder="请输入分类名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="propertyCategoryOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <!--资产信息-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="72px">
          <el-form-item label="资产编号" prop="cowinNum">
            <el-input
              v-model="queryParams.cowinNum"
              placeholder="请输入资产编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <!--<el-form-item label="股份编号" prop="cheryNum">
            <el-input
              v-model="queryParams.cheryNum"
              placeholder="请输入股份编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>-->
          <el-form-item label="资产品牌" prop="brand">
            <el-input
              v-model="queryParams.brand"
              placeholder="请输入资产品牌"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="资产型号" prop="modelNum">
            <el-input
              v-model="queryParams.modelNum"
              placeholder="请输入资产型号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="所属位置" prop="location">
            <el-input
              v-model="queryParams.location"
              placeholder="请输入所属位置"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="资产状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择资产状态" clearable size="small">
              <el-option
                v-for="dict in statusOptions"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="入库时间">
            <el-date-picker v-model="dateRange"
                            size="small"
                            style="width: 240px"
                            value-format="yyyy-MM-dd"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPerm="['property_add']"
            >新 增
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleEdit"
              v-hasPerm="['property_edit']"
            >修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDel"
              v-hasPerm="['property_del']"
            >删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              icon="el-icon-upload2"
              size="mini"
              @click="handleImport"
              v-hasPerm="['property_import']"
            >导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPerm="['property_export']"
            >导出
            </el-button>
          </el-col>
          <div class="top-right-btn">
            <el-tooltip class="item" effect="dark" content="刷新" placement="top">
              <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery"/>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
              <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch"/>
            </el-tooltip>
          </div>
        </el-row>

        <el-table v-loading="loading" :data="propertyList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="序号" type="index" align="center" show-overflow-tooltip width="50px">
          </el-table-column>
          <!--          <el-table-column label="id" align="center" prop="id"/>-->
          <el-table-column label="资产编号" align="center" prop="cowinNum"/>
          <el-table-column label="品牌" align="center" prop="brand"/>
          <el-table-column label="型号" align="center" prop="modelNum"/>
          <el-table-column label="规格" align="center" prop="specification"/>
          <el-table-column label="硬盘容量" align="center" prop="hardDriveCapacity"/>
          <el-table-column label="内存容量" align="center" prop="memoryCapacity"/>
          <el-table-column label="cpu" align="center" prop="cpu"/>
          <el-table-column label="入库时间" align="center" prop="inTime" width="180">
            <template slot-scope="scope">
              <span>{{ scope.row.inTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="所属分类" align="center" prop="categoryName"/>

          <el-table-column label="所属位置" align="center" prop="location"/>
          <!--          <el-table-column label="资产描述" align="center" prop="info"/>-->
          <el-table-column label="资产状态" align="center" prop="status" :formatter="statusFormat"/>
          <!--<el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>-->
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view "
                @click="handleDetail(scope.row)"
                v-hasPerm="['property_detail']"
              >详情
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleEdit(scope.row)"
                v-hasPerm="['property_edit']"
              >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDel(scope.row)"
                v-hasPerm="['property_del']"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.current"
          :limit.sync="queryParams.size"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 资产信息详情对话框 -->
    <el-dialog :title="title" :visible.sync="openDetail">
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="资产编号" prop="cowinNum">
              <el-input v-model="form.cowinNum" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产品牌" prop="brand">
              <el-input v-model="form.brand" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产型号" prop="modelNum">
              <el-input v-model="form.modelNum" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产规格" prop="specification">
              <el-input v-model="form.specification" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="序列号" prop="serialNum">
              <el-input v-model="form.serialNum" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="硬盘容量" prop="hardDriveCapacity">
              <el-input v-model="form.hardDriveCapacity" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="内存容量" prop="memoryCapacity">
              <el-input v-model="form.memoryCapacity" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="CPU" prop="cpu">
              <el-input v-model="form.cpu" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属分类" prop="categoryName">
              <el-input v-model="form.categoryName" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属位置" prop="location">
              <el-input v-model="form.location" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入库时间" prop="inTime">
              <el-date-picker readonly="readonly"
                              clearable size="small"
                              v-model="form.inTime"
                              type="date"
                              value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="使用年限" prop="workingLife">
              <el-input v-model="form.workingLife" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="form.remarks" type="textarea" readonly="readonly"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="资产状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in statusOptions"
                  :key="dict.value"
                  :label="dict.value"
                  v-if="form.status === dict.value"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="form.status === 'IN_STOCK'">
          <el-button type="success" plain @click="handleReceive()" v-hasPerm="['propertyRecord_add']">领 取</el-button>
          <el-button type="warning" plain @click="handleWaitScrap()" v-hasPerm="['property_wait_scrap']">待 报 废</el-button>
          <el-button type="danger" plain @click="handleInService()" v-hasPerm="['property_in_service']">维 修 中</el-button>
        </div>
        <div v-if="form.status === 'IN_SERVICE' || form.status === 'WAIT_SCRAP'">
          <el-button type="success" plain @click="handleInStock()" v-hasPerm="['property_in_stock']">恢 复 正 常</el-button>
        </div>
        <br>
        <el-table v-loading="loading" :data="propertyRecordList">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="序号" type="index" align="center" show-overflow-tooltip width="50px">
          </el-table-column>
          <!--          <el-table-column label="id" align="center" prop="id"/>-->
          <el-table-column label="使用人" align="center" prop="username"/>
          <el-table-column label="工号" align="center" prop="jobId"/>
          <el-table-column label="一级部门" align="center" prop="firstDeptName"/>
          <el-table-column label="二级部门" align="center" prop="secondDeptName"/>
          <el-table-column label="三级部门" align="center" prop="thirdDeptName"/>
          <el-table-column label="领取时间" align="center" prop="receiveTime"/>
          <el-table-column label="归还时间" align="center" prop="backTime"/>
          <el-table-column label="使用状态" align="center" prop="useStatus" :formatter="useStatusFormat"/>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.useStatus == 1"
                size="mini"
                type="text"
                icon="el-icon-back"
                @click="handleBack(scope.row)"
                v-hasPerm="['propertyRecord_edit']"
              >归还
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 资产使用记录操作 -->
    <el-dialog :title="titleTwo" :visible.sync="openRecord">
      <el-form ref="recordForm" :model="recordForm" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12" v-if="false">
            <el-form-item label="资产id" prop="propertyId">
              <el-input v-model="recordForm.propertyId" placeholder="请输入姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="username" v-if="recordForm.id === undefined">
              <el-input v-model="recordForm.username" placeholder="请输入姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工号" prop="jobId" v-if="recordForm.id === undefined">
              <el-input v-model="recordForm.jobId" placeholder="请输入工号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="一级部门" prop="firstDeptName" v-if="recordForm.id === undefined">
              <el-input v-model="recordForm.firstDeptName" placeholder="请输入一级部门"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="二级部门" prop="secondDeptName" v-if="recordForm.id === undefined">
              <el-input v-model="recordForm.secondDeptName" placeholder="请输入二级部门"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="三级部门" prop="thirdDeptName" v-if="recordForm.id === undefined">
              <el-input v-model="recordForm.thirdDeptName" placeholder="请输入三级部门"/>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="recordForm.id === undefined">
            <el-form-item label="领取时间" prop="receiveTime">
              <el-date-picker
                clearable size="small" style="width: 240px"
                v-model="recordForm.receiveTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择领取时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="recordForm.id !== undefined">
            <el-form-item label="归还时间" prop="backTime">
              <el-date-picker
                clearable size="small" style="width: 240px"
                v-model="recordForm.backTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择归还时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRecordForm">确 定</el-button>
        <el-button @click="cancelRecord">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改资产信息对话框 -->
    <el-dialog :title="title" :visible.sync="open">
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="资产编号" prop="cowinNum">
              <el-input v-model="form.cowinNum" placeholder="请输入资产编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产品牌" prop="brand">
              <el-input v-model="form.brand" placeholder="请输入资产品牌"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产型号" prop="modelNum">
              <el-input v-model="form.modelNum" placeholder="请输入资产型号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产规格" prop="specification">
              <el-input v-model="form.specification" placeholder="请输入资产规格"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="序列号" prop="serialNum">
              <el-input v-model="form.serialNum" placeholder="请输入序列号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="硬盘容量" prop="hardDriveCapacity">
              <el-input v-model="form.hardDriveCapacity" placeholder="请输入硬盘容量"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="内存容量" prop="memoryCapacity">
              <el-input v-model="form.memoryCapacity" placeholder="请输入内存容量"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="CPU" prop="cpu">
              <el-input v-model="form.cpu" placeholder="请输入CPU"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属位置" prop="location">
              <el-input v-model="form.location" placeholder="请输入所属位置"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="使用年限" prop="workingLife">
              <el-input v-model="form.workingLife" placeholder="请输入使用年限"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属分类" prop="categoryId">
              <treeselect v-model="form.categoryId" :options="propertyCategoryOptions" :normalizer="normalizer"
                          placeholder="请选择归属分类"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入库时间" prop="inTime">
              <el-date-picker clearable size="small" style="width: auto"
                              v-model="form.inTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择入库时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="form.remarks" type="textarea" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 资产导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :on-error="handleFileError"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的资产数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProperty,
  getProperty,
  delProperty,
  addProperty,
  editProperty,
  exportProperty,
  waitScrapProperty,
  inServiceProperty,
  inStockProperty,
  importTemplate
} from "@/api/it/property";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {propertyCategoryTree} from "@/api/it/propertyCategory";
import {addPropertyRecord, editPropertyRecord, getPropertyRecord, getPropertyRecords} from "@/api/it/PropertyRecord";
import {getAccessToken} from "@/utils/auth";

export default {
  name: "Property",
  components: {Treeselect},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 资产信息表格数据
      propertyList: [],
      // 资产使用记录表格数据
      propertyRecordList: [],
      // 弹出层标题(第一层)
      title: "",
      // 弹出层标题(第二层)
      titleTwo: "",
      // 资产分类名称树选项
      propertyCategoryOptions: undefined,
      // 是否显示弹出层(修改\新增)
      open: false,
      // 是否显示弹出层(详情)
      openDetail: false,
      // 是否显示弹出层(资产归还)
      openRecord: false,
      // 资产id
      propertyId: undefined,
      // 资产分类名称
      name: undefined,
      // 日期范围
      dateRange: [],
      // 记录状态(0-使用完,1-使用中)字典
      useStatusOptions: [],
      // 资产状态字典
      statusOptions: [],
      // 资产导入参数
      upload: {
        // 是否显示弹出层（资产导入）
        open: false,
        // 弹出层标题（资产导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的资产数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getAccessToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/it/property/importProperty"
      },
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        cowinNum: undefined,
        brand: undefined,
        modelNum: undefined,
        specification: undefined,
        serialNum: undefined,
        hardDriveCapacity: undefined,
        memoryCapacity: undefined,
        cpu: undefined,
        inTime: undefined,
        workingLife: undefined,
        categoryId: undefined,
        location: undefined,
        remarks: undefined,
        status: undefined,
        createTime: undefined,
      },
      // 显示搜索条件
      showSearch: true,
      // 表单参数
      form: {},
      // 使用记录表单参数
      recordForm: {},
      defaultProps: {
        children: "children",
        label: "name"
      },
      // 表单校验
      rules: {
        cowinNum: [
          {required: true, message: "资产编号不能为空", trigger: "blur"}
        ],
        inTime: [
          {required: true, message: "入库时间不能为空", trigger: "blur"}
        ],
        categoryId: [
          {required: true, message: "资产分类不能为空", trigger: "blur"}
        ],
        brand: [
          {required: true, message: "资产品牌不能为空", trigger: "blur"}
        ],
        modelNum: [
          {required: true, message: "资产型号不能为空", trigger: "blur"}
        ],
        specification: [
          {required: true, message: "资产规格不能为空", trigger: "blur"}
        ],
        serialNum: [
          {required: true, message: "序列号不能为空", trigger: "blur"}
        ],
        location: [
          {required: true, message: "所属位置不能为空", trigger: "blur"}
        ],
        workingLife: [
          {required: true, message: "使用年限不能为空", trigger: "blur"}
        ],
        username: [
          {required: true, message: "姓名不能为空", trigger: "blur"}
        ],
        jobId: [
          {required: true, message: "工号不能为空", trigger: "blur"}
        ],
        firstDeptName: [
          {required: true, message: "一级部门不能为空", trigger: "blur"}
        ],
        secondDeptName: [
          {required: true, message: "二级部门不能为空", trigger: "blur"}
        ],
        receiveTime: [
          {required: true, message: "领取时间不能为空", trigger: "blur"}
        ],
        backTime: [
          {required: true, message: "归还时间不能为空", trigger: "blur"}
        ],
      }
    };
  },
  watch: {
    // 根据名称筛选分类名称树
    name(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    this.getPropertyCategoryTree();
    this.getDicts("property_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("use_status").then(response => {
      this.useStatusOptions = response.data;
    });
  },
  methods: {
    /** 查询资产信息列表 */
    getList() {
      this.loading = true;
      listProperty(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.propertyList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 转换资产分类数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
    /** 查询资产分类名称下拉树结构 */
    getPropertyCategoryTree() {
      propertyCategoryTree().then(response => {
        this.propertyCategoryOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      console.log('value:' + JSON.stringify(value))
      console.log('data:' + JSON.stringify(data))
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.categoryId = data.id;
      this.getList();
    },
    // 资产状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 记录使用状态(0-使用完,1-使用中)字典翻译
    useStatusFormat(row, column) {
      return this.selectDictLabel(this.useStatusOptions, row.useStatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openDetail = false;
      this.openRecord = false;
      this.reset();
      this.recordReset();
    },
    // 关闭记录操作界面按钮
    cancelRecord() {
      this.openRecord = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        cowinNum: undefined,
        brand: undefined,
        modelNum: undefined,
        specification: undefined,
        serialNum: undefined,
        hardDriveCapacity: undefined,
        memoryCapacity: undefined,
        cpu: undefined,
        inTime: undefined,
        workingLife: undefined,
        category: undefined,
        location: undefined,
        status: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remarks: undefined,
        delFlag: undefined,
        propertyRecordList: undefined
      };
      this.resetForm("form");
    },
    // 使用记录表单重置
    recordReset() {
      this.recordForm = {
        id: undefined,
        propertyId: undefined,
        username: undefined,
        jobId: undefined,
        firstDeptName: undefined,
        secondDeptName: undefined,
        thirdDeptName: undefined,
        receiveTime: undefined,
        backTime: undefined,
        useStatus: undefined,
      };
      this.resetForm("recordForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 资产领取操作 */
    handleReceive() {
      this.recordReset();
      this.recordForm.propertyId = this.form.id;
      this.openRecord = true;
      this.titleTwo = "资产领取"
    },
    /** 资产待报废操作 */
    handleWaitScrap() {
      const property = this.form;
      this.$confirm('是否确认该资产为待报废状态?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return waitScrapProperty(property);
      }).then(() => {
        this.openDetail = false;
        this.getList();
        this.msgSuccess("操作成功");
      }).catch(function () {
      });
    },
    /** 资产维修中操作 */
    handleInService() {
      const property = this.form;
      this.$confirm('是否确认该资产为维修中?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return inServiceProperty(property);
      }).then(() => {
        this.openDetail = false;
        this.getList();
        this.msgSuccess("操作成功");
      }).catch(function () {
      });
    },
    /** 资产在库(恢复正常)操作 */
    handleInStock() {
      const property = this.form;
      this.$confirm('是否确认该资产恢复正常?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return inStockProperty(property);
      }).then(() => {
        this.openDetail = false;
        this.getList();
        this.msgSuccess("操作成功");
      }).catch(function () {
      });
    },
    /** 资产归还操作 */
    handleBack(row) {
      this.recordReset();
      const id = row.id
      getPropertyRecord(id).then(response => {
        this.recordForm = response.data;
        this.openRecord = true;
        this.titleTwo = "资产归还"
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资产信息";
    },
    /** 修改按钮操作 */
    handleEdit(row) {
      this.reset();
      const id = row.id || this.ids
      getProperty(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改资产信息";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id
      getProperty(id).then(response => {
        this.form = response.data;
        this.openDetail = true;
        this.title = "资产信息详情";
      });
      getPropertyRecords(id).then(response => {
        this.propertyRecordList = response.data;
      })
    },
    /** 资产使用操作 */
    submitRecordForm() {
      this.$refs["recordForm"].validate(valid => {
        if (valid) {
          if (this.recordForm.id !== undefined) {
            editPropertyRecord(this.recordForm).then(response => {
              if (response.code === 0) {
                this.msgSuccess("归还成功");
                this.openRecord = false;
                this.openDetail = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addPropertyRecord(this.recordForm).then(response => {
              if (response.code === 0) {
                this.msgSuccess("领取成功");
                this.openRecord = false;
                this.openDetail = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            })
          }
        }
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            editProperty(this.form).then(response => {
              if (response.code === 0) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addProperty(this.form).then(response => {
              if (response.code === 0) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDel(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除资产信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delProperty(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function () {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有资产信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportProperty(queryParams);
      }).then(response => {
        this.download(response.data);
      }).catch(function () {
      });
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "资产导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.data);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.data, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    handleFileError(err, file, fileList) {
      this.msgError(err)
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
